package zhoug.common.adapters.recycler2;


import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import zhoug.common.R;

/**
 * @Author 35574
 * @Date 2021/3/3
 * @Description
 */
public class SimpleLoadMoreView extends LoadMoreView {

    private View root;
    private View idleView;
    private View loadingView;
    private View successView;
    private View failView;
    private View endView;

    protected View getLoadMoeView(ViewGroup parent) {
         root = LayoutInflater.from(parent.getContext()).inflate(R.layout.common_load_more_view, parent, false);
        idleView = root.findViewById(R.id.load_more_default);
        loadingView = root.findViewById(R.id.load_more_loading);
        failView = root.findViewById(R.id.load_more_error);
        endView = root.findViewById(R.id.load_more_end);
        return root;
    }


    /**
     * 初始状态
     */
    protected void onIdle() {
        if (root != null) {
            idleView.setVisibility(View.VISIBLE);
            loadingView.setVisibility(View.GONE);
            endView.setVisibility(View.GONE);
            failView.setVisibility(View.GONE);
        }


    }

    /**
     * 正在加载
     */
    protected void onLoading() {
        if (root != null) {
            idleView.setVisibility(View.GONE);
            loadingView.setVisibility(View.VISIBLE);
            failView.setVisibility(View.GONE);
            endView.setVisibility(View.GONE);
        }

    }

    /**
     * 加载成功
     */
    protected void onSuccess() {
        onIdle();
    }

    /**
     * 加载失败
     */
    protected void onFail() {
        if (root != null) {
            idleView.setVisibility(View.GONE);
            loadingView.setVisibility(View.GONE);
            failView.setVisibility(View.VISIBLE);
            endView.setVisibility(View.GONE);
        }

    }

    /**
     * 没有更多数据了
     */
    protected void onEnd() {
        if (root != null) {
            idleView.setVisibility(View.GONE);
            loadingView.setVisibility(View.GONE);
            failView.setVisibility(View.GONE);
            if(getStatus()==END_GONE){
                endView.setVisibility(View.GONE);
            }else{
                endView.setVisibility(View.VISIBLE);
            }
        }

    }

}
